package com.cat.chapter038;

import java.util.ArrayList;
import java.util.List;

/**
 * @author cat
 * @description https://leetcode.cn/problems/subsets/
 * @create 2025/7/8 08:25
 * @since JDK17
 */

public class Solution03 {
    public List<List<Integer>> answer = new ArrayList<>();
    public List<Integer> list = new ArrayList<>();
    public List<List<Integer>> subsets(int[] nums) {
        f(nums, 0, nums.length);
        return answer;
    }

    public void f(int[] nums, int cur, int n) {
        if (cur == n) {
            answer.add(new ArrayList<>(list));
            return;
        }
        // 不取
        f(nums, cur + 1, n);
        // 取
        list.add(nums[cur]);
        f(nums, cur + 1, n);
        list.remove(list.size() - 1);   // 将刚刚加入的数字删除
    }
}
